<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>进度条</title>
    <style>
        .fa {
            width: 400px;
            height: 20px;
            border: 1px solid #000;
            position: relative;
        }

        .son {
            width: 0;
            height: 100%;
            background-color: #75ddac;
        }
    </style>
</head>

<body>
    <div class="fa">
        <div class="son">
            <span>0</span><span>%</span>
        </div>
    </div>
    <button id="btn">安装</button>
    <script>
        let btn = document.getElementById('btn');
        let div = document.getElementsByTagName('div')
        let span = document.getElementsByTagName('span')
        let timer = null

        btn.onclick = () => {
            let num = 0
            // 清除叠加&&执行进度条
            if (timer == null) {
                timer = setInterval(() => {
                    num += 10

                    // 宽递增
                    div[1].style.width = num + 'px'

                    // 百分比递增
                    span[0].innerText = Math.ceil(num / 400 * 100)

                    if (num == 400) {
                        clearInterval(timer)
                    }

                    // 文字递增
                }, 100)
            }

        }
    </script>
</body>

</html>